
/*
*Released on 28th June 2008.
*Any violations can be reported at paritosh@wikiocean.net
*What is treated as violations can be found at www.wikiocean.net/ppl1-voilations*
******************************************************************************
* The contents of this file are subject to POOL Public License 1.0 and later.
* POOL Public License is based on Affero GPL v3 and additional conditions.
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the Affero GPL v3 License at http://www.gnu.org/licenses/agpl.html
* You may obtain a copy of the POOL Public License 1.0 or later at www.wikiocean.net/license/ppl.html
* Software distributed under POOL Public License 1.0 is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Initial Developer of the Original Code is Paritosh Pungaliya (C) 2008. All Rights Reserved.
******************************************************************************
* Objective of the additional terms (license)
* 1) Is to extend the software freedom to freedom to work.
* 2) To ensure that knowledge is free from monopoly of agencies.
* 3) To avoid a situation where big corporate or investor can buy out free software groups and companies and then start milking the communities built around it.
* (this trend can be seen how the freedom is curtailed in companies that get Venture Capital funding.)
******************************************************************************
*/

package  sms;

import logger.PoolLogger;
import dbmanager.DBManager;

public class SMSDetails 
{
	public boolean ERROR=false;
	String data; 
	String status;
	String mobileNumber;
	String date;
	PoolLogger pl;
	
	public SMSDetails() {
		// logger
		pl = (PoolLogger) PoolLogger.getLogger(this.getClass().getName());
	}
	
	public void generate(String message, String modelName)
	{
		 if(message.indexOf("ERROR") != -1 || message.indexOf(':') <= 0)
		 {
		        ERROR = false;
		        return;
		 }
		int startOfMessage = message.indexOf("\r", message.indexOf(":") + 1) + 2;
	    int endOfMessage = message.length();
	    if(modelName.equals("HUAWEI"))
	    {
	        startOfMessage = message.indexOf("\r", message.indexOf(":") + 1) + 2;
	        System.out.println((new StringBuilder()).append("start Of Message : ").append(startOfMessage).toString());
			pl.info((new StringBuilder()).append("start Of Message : ").append(startOfMessage).toString());
			pl.debug((new StringBuilder()).append("start Of Message : ").append(startOfMessage).toString());
			pl.warn((new StringBuilder()).append("start Of Message : ").append(startOfMessage).toString());
			pl.fatal((new StringBuilder()).append("start Of Message : ").append(startOfMessage).toString());
			pl.error((new StringBuilder()).append("start Of Message : ").append(startOfMessage).toString());
			pl.trace((new StringBuilder()).append("start Of Message : ").append(startOfMessage).toString());
	        endOfMessage = message.length();
	        System.out.println((new StringBuilder()).append("end Of Message : ").append(endOfMessage).toString());
			pl.info((new StringBuilder()).append("end Of Message : ").append(endOfMessage).toString());
			pl.debug((new StringBuilder()).append("end Of Message : ").append(endOfMessage).toString());
			pl.warn((new StringBuilder()).append("end Of Message : ").append(endOfMessage).toString());
			pl.fatal((new StringBuilder()).append("end Of Message : ").append(endOfMessage).toString());
			pl.error((new StringBuilder()).append("end Of Message : ").append(endOfMessage).toString());
			pl.trace((new StringBuilder()).append("end Of Message : ").append(endOfMessage).toString());
	    }
	    if(endOfMessage - 8 < 25)
	    {
	        ERROR = false;
	        return;
	    }
	
		if(modelName.equals("HUAWEI"))
        {
            data = message.substring(startOfMessage, endOfMessage - 8);
            System.out.println((new StringBuilder()).append("SMS is : ").append(data).toString());
			pl.info((new StringBuilder()).append("SMS is : ").append(data).toString());
			pl.debug((new StringBuilder()).append("SMS is : ").append(data).toString());
			pl.warn((new StringBuilder()).append("SMS is : ").append(data).toString());
			pl.fatal((new StringBuilder()).append("SMS is : ").append(data).toString());
			pl.error((new StringBuilder()).append("SMS is : ").append(data).toString());
			pl.trace((new StringBuilder()).append("SMS is : ").append(data).toString());
            int start = message.indexOf(',');
            date = message.substring(start+1, message.indexOf(',',start+1));
            date = date.replace("<", "");
            date = date.replace("/", "-");
            date = date.replace(">", "");
            status = message.substring(message.indexOf(':') + 1, message.indexOf(','));
            status = status.trim();
            status = status.substring(1, status.length() - 1);
            System.out.println((new StringBuilder()).append("The status is : ").append(status).toString());
			pl.info((new StringBuilder()).append("The status is : ").append(status).toString());
			pl.debug((new StringBuilder()).append("The status is : ").append(status).toString());
			pl.warn((new StringBuilder()).append("The status is : ").append(status).toString());
			pl.fatal((new StringBuilder()).append("The status is : ").append(status).toString());
			pl.error((new StringBuilder()).append("The status is : ").append(status).toString());
			pl.trace((new StringBuilder()).append("The status is : ").append(status).toString());
            mobileNumber = message.substring(message.indexOf(':') + 1, message.indexOf(','));
            mobileNumber = mobileNumber.trim();
            System.out.println((new StringBuilder()).append("Mobile Number is : ").append(mobileNumber).toString());
			pl.info((new StringBuilder()).append("Mobile Number is : ").append(mobileNumber).toString());
			pl.debug((new StringBuilder()).append("Mobile Number is : ").append(mobileNumber).toString());
			pl.warn((new StringBuilder()).append("Mobile Number is : ").append(mobileNumber).toString());
			pl.fatal((new StringBuilder()).append("Mobile Number is : ").append(mobileNumber).toString());
			pl.error((new StringBuilder()).append("Mobile Number is : ").append(mobileNumber).toString());
			pl.trace((new StringBuilder()).append("Mobile Number is : ").append(mobileNumber).toString());
        }
        ERROR = true;
	}
	public boolean getError()
	{
		return ERROR;
	}
	
	public String getData() {
		return data;
	}
	
	public String getNumber()
	{
		if(mobileNumber.indexOf("0")==0)
		{
			mobileNumber = "+91"+mobileNumber.substring(1);
		}
		return mobileNumber;
	}
	
	public String getDate() {
		return date;
	}
	
	public String getStatus() {
		return status;
	}
}
